#ifndef PM_TASK_H_INCLUDED
#define PM_TASK_H_INCLUDED

#include "pm/dbobject.h"
#include "pm/criteria.h"
#include <wx/datetime.h>

namespace pm
{

class Task : public db::Table
{
public:
	static const wxString TABLE_NAME;

	db::text   name;
	db::real   unit_cost;
	db::real   quantity;
	db::date   end_date;
	db::text   comment;
	db::ID     id_project;
	db::ID     id_tag;

public:
	Task();
	Task(wxSQLite3ResultSet& res);

	double cost() const { return unit_cost() * quantity(); }
	
	bool finished() const { return cost() == 0.0; }

	// DB
	virtual db::update_value_t prepare_insert(wxSQLite3Database& db);
	virtual db::update_value_t prepare_update(wxSQLite3Database& db);
};

typedef std::list<Task> ListTask;

/**
 * \class GetTasksByProject
 */
struct GetTasksByProject : public ICriteriaForEach<Task>
{
	db::ID    id_project;
	
	GetTasksByProject(const db::ID& idProject);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * \class GetTasksTodoByProject
 */
struct GetTasksTodoByProject : public GetTasksByProject
{
	GetTasksTodoByProject(const db::ID& idProject);
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

/**
 * \class GetTasksDoneByProject
 */
struct GetTasksDoneByProject : public GetTasksByProject
{
	GetTasksDoneByProject(const db::ID& idProject);
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

} // namespace pm

#endif // PM_TASK_H_INCLUDED
